// @ts-ignore
import api from "@/api/http";
import { ApiResponse, ListResponse } from "@/api/types/ApiResponse";
import { SearchKeyQueryParam } from "@/api/types/QueryParam";


export interface SysAppResponse {
  id?: string | number;
  appName: string;
  appCode: string;
  appWebUrl: string;
  appApiUrl: string;
  disabled: string;
  deleted?: string | number;
}


/**
 * 查询列表
 * @param query
 */
export const doSelectPageList = (query: SelectSysAppListQueryParam): Promise<ListResponse<SysAppResponse>> => {
  console.log(query);
  return api.doGet("/SysApp/sysTbApp/selectPageList", query);
};
/**
 * 根据ID查询
 * @param id
 */
export const selectById = (id: string | number): Promise<ApiResponse<SysAppResponse>> => {
  return api.doGet("/SysApp/sysTbApp/selectById", { id: id });
};
/**
 * 新增
 * @param id
 */
export const doSaveEntity = (data: any): Promise<ApiResponse<boolean>> => {
  return api.doPost("/SysApp/sysTbApp/save", data);
};
/**
 * 修改
 * @param id
 */
export const doUpdateEntity = (data: any): Promise<ApiResponse<boolean>> => {
  return api.doPost("/SysApp/sysTbApp/update", data);
};
/**
 * 逻辑删除
 * @param id
 */
export const doLogicDelete = (ids: Array<string | number> | number | string): Promise<ApiResponse<boolean>> => {
  let data: any[] = [];
  if (Array.isArray(ids)) {
    data = ids;
  } else {
    data = [ids];
  }
  return api.doPost("/SysApp/sysTbApp/logicDelete", data);
};
/**
 * 物理删除
 * @param id
 */
export const doDelete = (ids: Array<string> | number | string): Promise<ApiResponse<boolean>> => {
  let data: any[] = [];
  if (Array.isArray(ids)) {
    data = ids;
  } else {
    data = [ids];
  }
  return api.doPost("/SysApp/sysTbApp/delete", data);
};
export const doExportJsonData = (ids: Array<string> | number | string): void => {
  window.location.href = (`${api.getBaseUrl()}/SysApp/sysTbApp/exportJsonData?ids=${ids.toString()}`);
};
export const doImportJsonData = async (fileList: File[]): Promise<ApiResponse<boolean>> => {
  const formData = new FormData();
  formData.append("file", fileList[0]);
  return api.doUpload("/SysApp/sysTbApp/importJsonData", formData);
};

export type SelectSysAppListQueryParam = SearchKeyQueryParam


export default {
  doSelectPageList,
  selectById,
  doDelete,
  doLogicDelete,
  doUpdateEntity,
  doSaveEntity,
  doExportJsonData,
  doImportJsonData
}
